//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Resource Application Block
//===============================================================================

using System.Configuration;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using EntLibContrib.Resource.Configuration;
#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
#endif

namespace EntLibContrib.Resource.Configuration.Tests
{
	[TestClass]
	public class XmlResourceProviderDataFixture
	{
		private const string name1 = "name1";
		private const string resourcePathName1 = "resourcePathName1";
		private const string resourceBaseName1 = "resourceBaseName1";

		[TestMethod]
		public void CanDeserializeSerializedConfiguration()
		{
			ResourceManagerSettings settings = new ResourceManagerSettings();

			XmlResourceProviderData data1 = new XmlResourceProviderData(name1, resourcePathName1, resourceBaseName1);
			settings.ResourceProviders.Add(data1);

			// needed to save configuration
			settings.ResourceManagers.Add(new ResourceManagerData("manager1", "xmlProvider1"));

			IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>();
			sections[ResourceManagerSettings.SectionName] = settings;
			IConfigurationSource configurationSource = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

			ResourceManagerSettings resourceManagerSettings = (ResourceManagerSettings)configurationSource.GetSection(ResourceManagerSettings.SectionName);

			Assert.IsNotNull(resourceManagerSettings);
			Assert.AreEqual(1, resourceManagerSettings.ResourceProviders.Count);
			Assert.IsNotNull(resourceManagerSettings.ResourceProviders.Get(name1));
			Assert.AreSame(typeof(XmlResourceProviderData), resourceManagerSettings.ResourceProviders.Get(name1).GetType());
			Assert.AreEqual(name1, resourceManagerSettings.ResourceProviders.Get(name1).Name);
			Assert.AreEqual(resourcePathName1, ( (XmlResourceProviderData)resourceManagerSettings.ResourceProviders.Get(name1) ).ResourcePathName);
			Assert.AreEqual(resourceBaseName1, ( (XmlResourceProviderData)resourceManagerSettings.ResourceProviders.Get(name1) ).ResourceBaseName);
		}
	}
}